package com.lize;

import java.util.*;

public class Generictest {

    public static void main(String[] args) {
        //用keyset来遍历

        HashSet<Student> set= new HashSet<Student>();
        set.add(new Student("小笨蛋",122));
        set.add(new Student("小天才",1));
        set.add(new Student("小垃圾",11));
        HashMap<String,Student> map=new HashMap<String, Student>();
         map.put("小笨蛋",new Student("小笨蛋",122));
         map.put("小天才",new Student("小天才",1));
         map.put("小垃圾",new Student("小垃圾",11));
         for(Student s:set){
             System.out.println("学生的名字=="+s.name+"  学生的年龄"+s.age);
         }
        Set<Map.Entry<String, Student>> entries = map.entrySet();
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
   while (iterator.hasNext()){


       Map.Entry<String, Student> next = iterator.next();
       System.out.println("学生的名字==："+next.getKey()+"学生对象："+next.getValue());


   }

    }
}
class Student{


    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}